package com.label.Web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.label.Model.Common.ResponseBean;
import com.label.Model.Do.Entity;
import com.label.Model.Do.TagInfo;
import com.label.Model.Query.*;
import com.label.Model.Vo.ActivityTagVo;
import com.label.Model.Vo.StuTagVo;
import com.label.Service.EntityService;
import com.label.Service.TagInfoService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.eclipse.jetty.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/entityTag")
public class EntityTagController {

    private final static Logger logger = LoggerFactory.getLogger(EntityTagController.class);

    @Resource
    private EntityService entityTagService;

    @Resource
    private TagInfoService tagInfoService;

    @RequestMapping("/getAllTagInfo")
    @RequiresAuthentication
    public ResponseBean getAllTagInfo(){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",tagInfoService.list());
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    @RequestMapping("/addTagInfo")
    @RequiresAuthentication
    public ResponseBean addTagInfo(@RequestBody TagInfoQuery tagInfoQuery){
        try {
            return new ResponseBean(HttpStatus.OK_200,"增加成功！",tagInfoService.addTagInfo(tagInfoQuery));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"增加失败！",null);
        }
    }

    //绑定标签，
    @RequestMapping("/entityAddTag")
    @RequiresAuthentication
    public ResponseBean entityAddTag(@RequestBody EntityQuery entityQuery){
        try {
            if(entityTagService.entityAddTag(entityQuery))
                return new ResponseBean(HttpStatus.OK_200,"增加成功！",true);
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"标签重复或错误！",null);
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"增加失败！",null);
        }
    }

    //删除标签
    @RequestMapping("/entityDelTag")
    @RequiresAuthentication
    public ResponseBean entityDelTag(@RequestBody EntityQuery entityQuery){
        try {
            if(entityTagService.entityDelTag(entityQuery))
                return new ResponseBean(HttpStatus.OK_200,"删除成功！",true);
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"删除失败！",null);
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"删除失败！",null);
        }
    }

    //情况，课程，学生，宿舍，班级
    @RequestMapping("/getAllCourseInfo")
    @RequiresAuthentication
    public ResponseBean getAllCourseInfo(){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getAllCourseInfo());
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    @RequestMapping("/findCourseInfo")
    @RequiresAuthentication
    public ResponseBean findCourseInfo(@RequestBody ActivityTagVo activityTagVo){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getOneCourseInfo(activityTagVo));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    //学生
    @RequestMapping("/getAllStuInfo")
    @RequiresAuthentication
    public ResponseBean getAllStuInfo(){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getAllStuInfo());
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    @RequestMapping("/findStuInfo")
    @RequiresAuthentication
    public ResponseBean findStuInfo(@RequestBody StuTagVoQuery stuTagVoQuery){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getOneStuInfo(stuTagVoQuery));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }


    //宿舍
    @RequestMapping("/getAllDorInfo")
    @RequiresAuthentication
    public ResponseBean getAllDorInfo(){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getAllDorInfo());
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    @RequestMapping("/findDorInfo")
    @RequiresAuthentication
    public ResponseBean findDorInfo(@RequestBody DorTagQuery dorTagQuery){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getOneDorInfo(dorTagQuery));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    //班级
    @RequestMapping("/getAllClassInfo")
    @RequiresAuthentication
    public ResponseBean getAllClassInfo(){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getAllClassInfo());
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }

    @RequestMapping("/findClassInfo")
    @RequiresAuthentication
    public ResponseBean findClassInfo(@RequestBody ClassTagQuery classTagQuery){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getOneClassInfo(classTagQuery));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }


    @RequestMapping("/getPoint")
    @RequiresAuthentication
    public ResponseBean getPoint(@RequestBody TagInfoQuery tagInfoQuery){
        try {
            return new ResponseBean(HttpStatus.OK_200,"查找成功！",entityTagService.getPoint(tagInfoQuery));
        }catch (Exception e){
            logger.info(e.getMessage());
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR_500,"查找失败！",null);
        }
    }
}
